
// const baseUrl = 'https://test-m.bashouj.com';// 测试环境
const baseUrl = 'https://m.bashouj.com';// 生产环境
const axiosZpz = function (url: string, type: 'GET' | 'POST' | 'DELETE', data: any) {
  wx.setStorageSync('key', 'value')
  return new Promise((reslove, reject) => {
    wx.request({
      method: type,
      header: { 'ut': wx.getStorageSync('token') },
      url: baseUrl + url,
      timeout: 10000,
      data: data,
      success: (res: any) => {
        if (res.data.code == 0) {
          reslove(res.data);
        } else {
          if (res.data.code === 90001) {
            wx.setStorageSync('token', '')
            wx.setStorageSync('phoneNum', '')
            wx.navigateTo({ url: '/pages/login/login' });
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            });
          }
          reject(res.data);
        }
      },
      fail: (err: any) => {
        reject(err)
      }
    })
  })
};
export { axiosZpz };